//===================================================================
// 西交投.NET产品框架 版权所有
//===================================================================
using System;
using XCI.Sys.Model;
using XCI.Sys.Service;
using XCI.Windows;

namespace XCI.Sys.Forms
{
    /// <summary>
    /// 系统序列详情
    /// </summary>
    public partial class FrmSeqDetails : BaseForm
    {
        public FrmSeqDetails(GridControlPlus gridControl)
        {
            InitializeComponent();
            tabPane.Grid = gridControl;
        }

        /// <summary>
        /// 页面加载事件
        /// </summary>
        private async void FrmSeqDetails_Load(object sender, EventArgs e)
        {
            await tabPane.BindingModelAsync();
        }

        /// <summary>
        /// 关闭按钮事件
        /// </summary>
        private void BtnCloseButton_Click(object sender, EventArgs e)
        {
            DialogCancel();
        }

        /// <summary>
        /// 标签页切换数据绑定
        /// </summary>
        private void TabPane1_PageBinding(object sender, DetailsFormPaneBindingEventArgs e)
        {
            e.Task = async () =>
            {
                switch (e.Current.TabPageName)
                {
                    case nameof(tabGeneral):
                        bindingSource.DataSource = string.IsNullOrEmpty(e.Current.Id) ? new SysSeq() : await SysSeqService.Instance.SelectByIdAsync(e.Current.Id);
                        break;
                    case nameof(tabHistory):
                        await historyLogGrid.LoadAsync(nameof(SysSeq), e.Current.Id);
                        break;
                }
            };
        }
    }
}